<?php
 Zend_Loader::loadClass("CodesUtility");
 Zend_Loader::loadClass("BaseDBRow");
 class Receipt extends BaseDBRow
 {
	const _tablename = "projecte_sales.receipts";
 	protected function setUp()
 	{
 		$this->_tableName = self::_tablename;		
 	}
	
	public function getReceipt($receipt_id) {
		
		Zend_Loader::loadClass("QueryCreator");	
		Zend_Loader::loadClass("Organization");
		Zend_Loader::loadClass("purchaseOrderDetail");
		Zend_Loader::loadClass("purchaseOrder");
		Zend_Loader::loadClass("SupplierPerformance");
		Zend_Loader::loadClass("SupplierPerformanceResult");
		
		$query = new QueryCreator();
		
		$query->addSelect(" b.name,a.date_receipt,po.po_no,a.supplier_org_id,a.receipt_id ");
		$query->addSelect(" sp.ssp_id,overall_rate,doa,unordered_organism,size,water_quantity,packing,sp.comments ");
		$query->addFrom($this->_tableName . " a ");
		$query->addJoin(" LEFT JOIN ". Organization::_tablename . " b on a.supplier_org_id = b.org_id ");
		$query->addJoin(" LEFT JOIN ". purchaseOrderDetail::_tablename ." podetail on podetail.po_detail_id = a.reference_id and a.source = 'PO' ");
		$query->addJoin(" LEFT JOIN ". purchaseOrder::_tablename . " po on po.po_id=podetail.po_id ");
		$query->addJoin(" LEFT JOIN ". SupplierPerformance::_tablename . " sp on sp.reference_receipt_id = a.receipt_id ");
		$query->addJoin(" LEFT JOIN ". SupplierPerformanceResult::_tablename . " spr on spr.ssp_id = sp.ssp_id");
		
		$query->addWhere(" a.receipt_id = ". $receipt_id);	
		
		$db = DBCon::instance();
		
		$result = $db->executeQuery($query->createSQL());
		return $result[0];
	}
 }
?>